﻿package 
{
	
	import controllers.AlbumController;
	import controllers.InfoController;
	import events.UserEvent;
	import flash.display.MovieClip;
	import flash.events.Event;
	import view.AlbumsView;
	import view.components.TabsMenu;
	
	import view.MainView;

	/**
	 * ...
	 * @author Slavshik Alexander
	 */
	[Frame(factoryClass="Splash")]
	[SWF(width="570"  , height = "430"  , frameRate = "31"  , backgroundColor = "#FFFFFF")]
	public class Main extends MovieClip
	{
		private var mainView:MainView;
		private var albumsView:AlbumsView;
		public static var instance:Main;
		public var icontroller:InfoController = new InfoController();
		public var acontroller:AlbumController = new AlbumController();
		
		public function Main():void {
			instance = this;
			addEventListener(Event.ADDED_TO_STAGE, loaded, false, 0, true);
		}
		private function loaded(event:Event):void {
			icontroller.init(loaderInfo.parameters);
			icontroller.addEventListener(UserEvent.INITED, onInited);
		}
		private function onInited(e:UserEvent):void {
			icontroller.removeEventListener(UserEvent.INITED, onInited);
			acontroller.getAlbums();
			mainView = new MainView();
			albumsView = new AlbumsView();
			switchToScreen(1);
		}
		public function switchToScreen(screen:int):void {
			switch(screen) {
				case 1:
					addChild(mainView);
				break;
				//AlbumsView
				case 2:
					if (mainView != null && contains(mainView)) removeChild(mainView);
					addChild(albumsView);
				break;
			}
		}
	}

}